oTargetsTarget = oUF:NewModule("oUF_TargetofTarget")
local M = DongleStub("MetrognomeNano")
local G = getfenv(0)

function oTargetsTarget:Enable()
        self:disableBlizzard()
        self:RegisterEvent("PLAYER_TARGET_CHANGED", "update")
        oUF.unit.targettarget = oUF.class.unit:new("targettarget")
        oUF.unit.targettarget:loadPosition()
        
	-- Metrognome stuff
	M:Register(self, "ToT", function() self:update() end, .5)
	M:Register(self, "checkToT", function() self:update() end, 5.0)
	M:Start("checkToT")
	
end

function oTargetsTarget:update()
        if(UnitExists("targettarget")) then
		oUF.unit.targettarget:updateAll()
	        oTargetsTarget:updateReaction()
	        M:Start("ToT", 20)
	end
end

function oTargetsTarget:updateReaction()
	local r, g, b = oUF:GetReactionColors("targettarget")
	oUF.unit.targettarget:SetBackdropBorderColor(r, g, b)
end

function oTargetsTarget:disableBlizzard() 
	G["TargetofTargetFrame"]:UnregisterAllEvents()
        G["TargetofTargetFrame"]:Hide()
end
